package waal.pc.frontend.config;

import java.awt.Color;
import java.awt.Component;

import javax.swing.DefaultListCellRenderer;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;

import waal.pc.backend.hub.Hub;


public class HubListCellRenderer extends DefaultListCellRenderer {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public Component getListCellRendererComponent(JList<? extends Object> list,
			Object value, int index, boolean isSelected, boolean cellHasFocus) {
		
		Hub hub = (Hub) value;
		JLabel l = new JLabel(hub.getName());
		l.setOpaque(true);
		boolean owning = hub.isMaster();
		Border border = new LineBorder(new Color(0,128,255), 2);

		if(isSelected) {
			l.setForeground(Color.BLACK);
			l.setBorder(border);
			if(owning) {
				l.setBackground(new Color(128, 255, 128));
			} else {
				if(!hub.isFree()) {
					l.setBackground(new Color(200, 200, 200));
				} else {
					l.setOpaque(true);
					//l.setBackground(new Color(200, 200, 255));
				}
			}
		} else  {
			l.setForeground(Color.BLACK);
			if(owning) {
				l.setBackground(new Color(128, 255, 128));
			} else {
				if(!hub.isFree()) {
					l.setBackground(new Color(200, 200, 200));
				} else {
					l.setOpaque(true);
				}
			}
		}
		
		return l;
	}

}
